package com.jinsilu.freight.ui.adapter;

import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.jinsilu.freight.R;
import com.jinsilu.freight.helper.ShowImageHelper;
import com.jinsilu.freight.http.response.RecordWhiteNoteBean;

import java.util.List;

/**
 * 白条消费明细列表
 *
 * @author byd
 * @time 2022/04/08 17:22
 */
public class BlankNoteConsumeDetailsAdapter extends BaseQuickAdapter<RecordWhiteNoteBean, BaseViewHolder> {

    public BlankNoteConsumeDetailsAdapter(@Nullable List<RecordWhiteNoteBean> data) {
        super(R.layout.item_blank_note_consume_details, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, RecordWhiteNoteBean item) {
        holder.setText(R.id.tv_station_name, String.format("%s", TextUtils.isEmpty(item.getStationName()) ? "" : item.getStationName()))
                .setText(R.id.tv_goods_name, String.format("%s", TextUtils.isEmpty(item.getGoodsName()) ? "" : item.getGoodsName()))
                .setText(R.id.tv_goods_attr, String.format("规格：%s", TextUtils.isEmpty(item.getGoodsSpecifications()) ? "" : item.getGoodsSpecifications()))
                .setText(R.id.tv_order_time, String.format("下单时间：%s", item.getCreateTime()))
                .setText(R.id.tv_actual_pay, String.format("￥%s", Math.abs(item.getPayMoney().floatValue())))
                .setText(R.id.tv_save_money, String.format("￥%s", item.getSumDiscount()));
        AppCompatImageView goodsImageView = holder.getView(R.id.iv_goods_photo);
        // 有商品图片展示商品图片 没有则展示logo
        if (TextUtils.isEmpty(item.getGoodsImg()))
            ShowImageHelper.showNormal(getContext(), R.mipmap.ic_launcher, goodsImageView);
        else
            ShowImageHelper.showNormal(getContext(), item.getGoodsImg(), goodsImageView);
    }
}
